<template>
  <div class="mobile-ecology">
    <div v-fade-in class="title">生态产品</div>
    <M-button v-slide-up @click="goMore" />
    <van-swipe
      v-slide-up
      class="swipe-container"
      :autoplay="5000"
      :show-indicators="true"
      indicator-color="#fff"
    >
      <van-swipe-item v-for="(group, groupIndex) in data" :key="groupIndex">
        <div class="card-list">
          <div
            v-slide-plus
            v-for="(item, index) in group"
            :key="index"
            class="card"
            @click="handleDetail(item)"
          >
            <div class="card-cover">
              <img v-if="item.cover" v-slide-plus :src="publicSrc(item.cover)" />
            </div>
            <div class="card-title">{{ item.name }}</div>
            <div class="card-desc">{{ item.synopsis }}</div>
          </div>
        </div>
      </van-swipe-item>
    </van-swipe>
  </div>
</template>
<script setup lang="ts">
import { publicSrc } from "@/utils/common";
import { useRouter } from "vue-router";

const router = useRouter();

defineProps({
  data: {
    type: Array as PropType<any[]>,
    default: () => [],
  },
});

const handleDetail = (item: any) => {
  router.push({ path: "/m/product", query: { id: item.id } });
};

const goMore = () => {
  router.push("/m/product");
};
</script>
<style lang="scss" scoped>
.mobile-ecology {
  padding: 1.25rem;
  height: 100vh;
  box-sizing: border-box;
  background: url("@/assets/home/carousel5.png") no-repeat;
  background-size: cover;
  .title {
    font-size: 20px;
    font-weight: 700;
    color: #fff;
    margin-top: 20%;
  }
  :deep(.more-btn) {
    position: static;
    display: inline-flex;
    margin-top: 8%;
    margin-bottom: 8%;
  }
  .swipe-container {
    margin-top: 1rem;
  }
  .card-list {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
    padding: 0 1rem;
  }
  .card {
    position: relative;
    background: rgba(255, 255, 255, 0.13);
    backdrop-filter: blur(15px);
    overflow: hidden;
    padding: 1rem 0.75rem 0.75rem 0.75rem;
    box-sizing: border-box;
    transition: all 0.5s;
    &::before {
      content: "";
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: 1px;
      transition: all 0.5s;
      background: linear-gradient(
        to right,
        rgba(255, 255, 255, 0.5),
        rgba(255, 255, 255, 0)
      );
    }
    &::after {
      content: "";
      position: absolute;
      top: 0;
      left: 0;
      width: 1px;
      height: 100%;
      transition: all 0.5s;
      background: linear-gradient(
        to bottom,
        rgba(255, 255, 255, 0.5),
        rgba(255, 255, 255, 0)
      );
    }
  }
  .card-cover {
    width: 100%;
    min-height: 7.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    img {
      width: 8.75rem;
      height: 8.75rem;
      object-fit: cover;
      transition: all 0.5s;
    }
  }
  .card-title {
    font-size: 16px;
    font-weight: 700;
    color: #fff;
    margin-top: 0.5rem;
    padding: 0 0.25rem;
    &::before {
      content: "";
      position: absolute;
      bottom: 0;
      left: 0;
      width: 100%;
      height: 1px;
      transition: all 0.5s;
      background: linear-gradient(
        to right,
        rgba(255, 255, 255, 0),
        rgba(255, 255, 255, 0.5)
      );
    }
    &::after {
      content: "";
      position: absolute;
      top: 0;
      right: 0;
      width: 1px;
      height: 100%;
      transition: all 0.5s;
      background: linear-gradient(
        to bottom,
        rgba(255, 255, 255, 0),
        rgba(255, 255, 255, 0.5)
      );
    }
  }
  .card-desc {
    font-size: 12px;
    line-height: 18px;
    color: rgba(255, 255, 255, 0.6);
    padding: 0.5rem 0.25rem 0 0.25rem;
    display: -webkit-box;
    text-overflow: ellipsis;
    line-clamp: 2;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    min-height: 36px;
  }
}
</style>
